<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="hadoop 大数据集群的搭建以及使用, 成大事">
    <meta name="description" content="hadoop 大数据集群的搭建以及使用">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="referrer" content="no-referrer-when-downgrade">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>hadoop 大数据集群的搭建以及使用 | 成大事</title>
    <link rel="stylesheet" type="text/css" href="/hexo/css/loading.css">
    <link rel="icon" type="image/png" href="/hexo/favicon.png">

    <link rel="stylesheet" type="text/css" href="/hexo/libs/awesome/css/all.min.css">
    <link rel="stylesheet" type="text/css" href="/hexo/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/hexo/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/hexo/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/hexo/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/hexo/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/hexo/css/my.css">

    <script src="/hexo/libs/jquery/jquery-3.6.0.min.js"></script>


<meta name="generator" content="Hexo 6.1.0"></head>




   <style>
    body{
       background-image: url(/medias/banner/bg.jpg);
       background-repeat:no-repeat;
       background-size: 100% 100%;
       background-attachment:fixed;
    }
</style>



<body>
    
  <div id="loading-box">
    <div class="loading-left-bg"></div>
    <div class="loading-right-bg"></div>
    <div class="spinner-box">
      <div class="configure-border-1">
        <div class="configure-core"></div>
      </div>
      <div class="configure-border-2">
        <div class="configure-core"></div>
      </div>
      <div class="loading-word">加载中...</div>
    </div>
  </div>
  <!-- 页面加载动画 -->
  <script>
    $(document).ready(function () {
      document.body.style.overflow = 'auto';
      document.getElementById('loading-box').classList.add("loaded")
    })
  </script>



    <!-- 白天和黑夜主题 -->
<div class="sum-moon-box">
  <a class="btn-floating btn-large waves-effect waves-light" onclick="switchNightMode()" title="切换主题" >
    <i id="sum-moon-icon" class="fas fa-sun" style="width:48px; height:48px; font-size: 28px;"></i>
  </a>
</div>

<script>
  function switchNightMode() {
    $('<div class="Cuteen_DarkSky"><div class="Cuteen_DarkPlanet"></div></div>').appendTo($('body')),
      setTimeout(function () {
        $('body').hasClass('DarkMode') 
        ? ($('body').removeClass('DarkMode'), localStorage.setItem('isDark', '0'), $('#sum-moon-icon').removeClass("fa-sun").addClass('fa-moon')) 
        : ($('body').addClass('DarkMode'), localStorage.setItem('isDark', '1'), $('#sum-moon-icon').addClass("fa-sun").removeClass('fa-moon')),
          
        setTimeout(function () {
          $('.Cuteen_DarkSky').fadeOut(1e3, function () {
            $(this).remove()
          })
        }, 2e3)
      })
  }
</script>
<div class="stars-con">
  <div id="stars"></div>
  <div id="stars2"></div>
  <div id="stars3"></div>  
</div>

<script>
    /* 模式判断 */
    if (localStorage.getItem('isDark') === '1') {
        document.body.classList.add('DarkMode');
        $('#sum-moon-icon').addClass("fa-sun").removeClass('fa-moon')
    } else {
        document.body.classList.remove('DarkMode');
        $('#sum-moon-icon').removeleClass("fa-sun").addClass('fa-moon')
    }
</script>

    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/hexo/" class="waves-effect waves-light">
                    
                    <img src="/hexo/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">成大事</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/hexo/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/hexo/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/hexo/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/hexo/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/hexo/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/hexo/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/hexo/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友链</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/hexo/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">成大事</div>
        <div class="logo-desc">
            
            Never really desperate, only the lost of the soul.
            
        </div>
    </div>

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/hexo/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/hexo/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/hexo/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/hexo/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/hexo/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/hexo/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/hexo/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友链
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/zhaojiuyi" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/zhaojiuyi" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/hexo/medias/index/1.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">hadoop 大数据集群的搭建以及使用</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/hexo/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        padding: 35px 0 15px 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        padding-bottom: 30px;
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/hexo/tags/hadoop/">
                                <span class="chip bg-color">hadoop</span>
                            </a>
                        
                            <a href="/hexo/tags/zookeeper/">
                                <span class="chip bg-color">zookeeper</span>
                            </a>
                        
                            <a href="/hexo/tags/kafka/">
                                <span class="chip bg-color">kafka</span>
                            </a>
                        
                            <a href="/hexo/tags/hbase/">
                                <span class="chip bg-color">hbase</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/hexo/categories/hadoop/" class="post-category">
                                hadoop
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2022-05-16
                </div>
                

                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    4k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    19 分
                </div>
                

                
            </div>
        </div>
        <hr class="clearfix">

        
        <!-- 是否加载使用自带的 prismjs. -->
        <link rel="stylesheet" href="/hexo/libs/prism/prism.css">
        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <h1 id="1-hadoop集群搭建及使用"><a href="#1-hadoop集群搭建及使用" class="headerlink" title="1.hadoop集群搭建及使用"></a>1.hadoop集群搭建及使用</h1><h2 id="1-集群规划；"><a href="#1-集群规划；" class="headerlink" title="(1).集群规划；"></a>(1).集群规划；</h2><p><img src="/hexo/2022/05/16/hadoop/image-20220516121650308.png" alt="image-20220516121650308"></p>
<h2 id="2-虚拟机准备；"><a href="#2-虚拟机准备；" class="headerlink" title="(2).虚拟机准备；"></a>(2).虚拟机准备；</h2><h3 id="1、创建虚拟机（具体步骤不再展示）；"><a href="#1、创建虚拟机（具体步骤不再展示）；" class="headerlink" title="1、创建虚拟机（具体步骤不再展示）；"></a>1、创建虚拟机（具体步骤不再展示）；</h3><p><img src="/hexo/2022/05/16/hadoop/image-20220516121741768.png" alt="image-20220516121741768"> </p>
<h3 id="2-、配置网络；"><a href="#2-、配置网络；" class="headerlink" title="2 、配置网络；"></a>2 、配置网络；</h3><h4 id="ping外网：ping-baidu-com"><a href="#ping外网：ping-baidu-com" class="headerlink" title="ping外网：ping baidu.com"></a>ping外网：ping baidu.com</h4><p><img src="/hexo/2022/05/16/hadoop/image-20220516121747924.png" alt="image-20220516121747924"> </p>
<h4 id="如果ping不通"><a href="#如果ping不通" class="headerlink" title="如果ping不通"></a>如果ping不通</h4><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#修改如下文件：</span>
<span class="token function">vi</span> /etc/sysconfig/network-scripts/ifcfg-ens-33</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516121754932.png" alt="image-20220516121754932"> </p>
<h4 id="重启网络服务："><a href="#重启网络服务：" class="headerlink" title="重启网络服务："></a>重启网络服务：</h4><p>service network restart</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516121802380.png" alt="image-20220516121802380"> </p>
<h4 id="配置静态IP："><a href="#配置静态IP：" class="headerlink" title="配置静态IP："></a>配置静态IP：</h4><p>打开VMware-&gt;编辑-&gt;虚拟机网络编辑器</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516121810372.png" alt="image-20220516121810372"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516121816889.png" alt="image-20220516121816889"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516121824390.png" alt="image-20220516121824390"> </p>
<p>查看IP：ip addr</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516140004855.png" alt="image-20220516140004855"> </p>
<h4 id="修改网卡的配置文件"><a href="#修改网卡的配置文件" class="headerlink" title="修改网卡的配置文件"></a>修改网卡的配置文件</h4><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token function">vi</span> /etc/sysconfig/network-scripts/ifcfg-ens-33
<span class="token comment">#修改并添加：（IP为静态）</span>
<span class="token assign-left variable">BOOTPROTO</span><span class="token operator">=</span>static
<span class="token assign-left variable">IPADDR</span><span class="token operator">=</span><span class="token number">192.168</span>.246.132
<span class="token assign-left variable">GATEWAY</span><span class="token operator">=</span><span class="token number">192.168</span>.246.2
<span class="token assign-left variable">DNS1</span><span class="token operator">=</span><span class="token number">192.168</span>.246.2</code></pre>

<p>如图所示</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516121832458.png" alt="image-20220516121832458"> </p>
<p>重启网络服务：service network restart</p>
<p>ping外网（查看是否可以ping通）：ping baidu.com </p>
<h3 id="3-克隆两台上述已配置的虚拟机；"><a href="#3-克隆两台上述已配置的虚拟机；" class="headerlink" title="3).克隆两台上述已配置的虚拟机；"></a>3).克隆两台上述已配置的虚拟机；</h3><p>关闭虚拟机：</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516121836984.png" alt="image-20220516121836984"> </p>
<p>点击下一页，</p>
<p>选择克隆类型时，创建完整克隆：</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516121842574.png" alt="image-20220516121842574"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#打开第二、三台虚拟机，进入：</span>
<span class="token function">vi</span> /etc/sysconfig/network-scripts/ifcfg-ens-33

<span class="token comment">#更改</span>
<span class="token assign-left variable">IPADDR</span><span class="token operator">=</span><span class="token number">192.168</span>.246.133  
<span class="token assign-left variable">IPADDR</span><span class="token operator">=</span><span class="token number">192.168</span>.246.134</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516121847510.png" alt="image-20220516121847510"> </p>
<p>重启网络服务并查看是否可以ping通外网。</p>
<h2 id="3-修改主机名；"><a href="#3-修改主机名；" class="headerlink" title="(3).修改主机名；"></a>(3).修改主机名；</h2><p>查看主机名：hostname</p>
<p>修改第一台主机名：sudo hostnamectl set-hostname hadoop1</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516121854101.png" alt="image-20220516121854101"> </p>
<p>修改第二台主机名：sudo hostnamectl set-hostname hadoop2</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516121858625.png" alt="image-20220516121858625"> </p>
<p>修改第三台主机名：sudo hostnamectl set-hostname hadoop3</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516121903823.png" alt="image-20220516121903823"> </p>
<p>三台都要修改ip与主机名的映射：sudo vi &#x2F;etc&#x2F;hosts</p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#添加：</span>
<span class="token number">192.168</span>.246.132 hadoop1

<span class="token number">192.168</span>.246.134 hadoop2

<span class="token number">192.168</span>.246.133 hadoop3</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516121908682.png" alt="image-20220516121908682"> </p>
<p>重启虚拟机生效：reboot</p>
<h2 id="4-配置免密登录"><a href="#4-配置免密登录" class="headerlink" title="(4).配置免密登录"></a>(4).配置免密登录</h2><p>在hadoop1机器上操作：ssh-keygen -t rsa</p>
<p>执行命令后，连续敲击三次回车键，生成公钥</p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#拷贝公钥：</span>
ssh-copy-id hadoop1

ssh-copy-id hadoop2

ssh-copy-id hadoop3</code></pre>

<p>由于我已拷贝过，所以显示已存在</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516121913155.png" alt="image-20220516121913155"> </p>
<p>进入hadoop2、hadoop3同样操作，实现可以使用ssh hadoop2、ssh hadoop3，不需要密码就能进入hadoop2、hadoop3</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516121917445.png" alt="image-20220516121917445"> </p>
<h2 id="5-编写分发脚本；"><a href="#5-编写分发脚本；" class="headerlink" title="(5).编写分发脚本；"></a>(5).编写分发脚本；</h2><p>输入：rsync –help</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516121922280.png" alt="image-20220516121922280"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#三台虚拟机安装rsync命令：</span>
<span class="token function">sudo</span> yum <span class="token function">install</span> <span class="token function">rsync</span> -y

<span class="token comment">#rsync与scp区别：用rsync做文件的复制比scp快，rsync只对差异文件作更新</span>

<span class="token comment">#在主目录创建bin目录：</span>
<span class="token function">mkdir</span> ~/bin

<span class="token comment">#创建分发脚本脚本：</span>
<span class="token function">vim</span> ~/bin/xsync</code></pre>

<p>脚本内容如下：</p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token shebang important">#!/bin/bash </span>
<span class="token comment">#1. 判断参数个数</span>
<span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token variable">$#</span> -lt <span class="token number">1</span> <span class="token punctuation">]</span>
<span class="token keyword">then</span> 
    <span class="token builtin class-name">echo</span> Not Enough Arguement<span class="token operator">!</span>
    <span class="token builtin class-name">exit</span><span class="token punctuation">;</span>
<span class="token keyword">fi</span>
<span class="token comment">#2. 遍历集群所有机器</span>
<span class="token comment">#注意，如果你的主机名命名和我不一样，下面这三个更换成你的主机名</span>
<span class="token keyword">for</span> <span class="token for-or-select variable">host</span> <span class="token keyword">in</span> hadoop1 hadoop2 hadoop3
<span class="token keyword">do</span> 
    <span class="token builtin class-name">echo</span> <span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">=</span>  <span class="token variable">$host</span>  <span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">==</span><span class="token operator">=</span>    
    <span class="token comment">#3. 遍历所有目录，挨个发送</span>
    <span class="token keyword">for</span> <span class="token for-or-select variable">file</span> <span class="token keyword">in</span> <span class="token variable">$@</span>
    <span class="token keyword">do</span>
    	<span class="token comment">#4 判断文件是否存在</span>
        <span class="token keyword">if</span> <span class="token punctuation">[</span> -e <span class="token variable">$file</span> <span class="token punctuation">]</span>
            <span class="token keyword">then</span>
             	<span class="token comment">#5. 获取父目录</span>
                <span class="token assign-left variable">pdir</span><span class="token operator">=</span><span class="token variable"><span class="token variable">$(</span><span class="token builtin class-name">cd</span> -P <span class="token punctuation">$(</span>dirname $file<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token builtin class-name">pwd</span><span class="token variable">)</span></span>
                <span class="token assign-left variable">fname</span><span class="token operator">=</span><span class="token variable"><span class="token variable">$(</span><span class="token function">basename</span> $file<span class="token variable">)</span></span>
                <span class="token function">ssh</span> <span class="token variable">$host</span> <span class="token string">"mkdir -p <span class="token variable">$pdir</span>"</span>
                <span class="token function">rsync</span> -av <span class="token variable">$pdir</span>/<span class="token variable">$fname</span> <span class="token variable">$host</span><span class="token builtin class-name">:</span><span class="token variable">$pdir</span>
            <span class="token keyword">else</span>
                <span class="token builtin class-name">echo</span> <span class="token variable">$file</span> does not exists<span class="token operator">!</span>                
        <span class="token keyword">fi</span>
    <span class="token keyword">done</span>
<span class="token keyword">done</span>    </code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516121927761.png" alt="image-20220516121927761"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#修改权限：</span>
<span class="token function">chmod</span> +x ~/bin/xsync

<span class="token comment">#测试：把xsync命令发送到hadoop2、hadoop3</span>

<span class="token comment">#进入目录：</span>
<span class="token builtin class-name">cd</span> ~/bin

<span class="token comment">#将xsync脚本发送到hadoop2、hadoop3：</span>
xsync xsync</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516121932285.png" alt="image-20220516121932285"> </p>
<h2 id="6-安装JDK"><a href="#6-安装JDK" class="headerlink" title="(6).安装JDK;"></a>(6).安装JDK;</h2><p>进入官网下载匹配的jdk8安装包，上传至linux：cd</p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token function">mkdir</span> soft

<span class="token function">mkdir</span> installfile

<span class="token builtin class-name">cd</span> ~/installfile</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516121937403.png" alt="image-20220516121937403"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#解压：</span>
<span class="token function">tar</span> -zxvf jdk-8u281-linux-x64.tar.gz.crdownload -C ~/soft

<span class="token comment">#切换到soft目录下：</span>
<span class="token builtin class-name">cd</span> /root/soft

<span class="token comment">#创建软连接：</span>
<span class="token function">ln</span> -s jdk1.8.0_281 jdk</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516121942242.png" alt="image-20220516121942242"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#配置环境变量：</span>
<span class="token function">vi</span> ~/.bashrc

<span class="token comment">#内容如下：</span>
<span class="token builtin class-name">export</span> <span class="token assign-left variable">JAVA_HOME</span><span class="token operator">=~</span>/soft/jdk

<span class="token builtin class-name">export</span> <span class="token assign-left variable">JRE_HOME</span><span class="token operator">=</span><span class="token variable">$&#123;JAVA_HOME&#125;</span>/jre

<span class="token builtin class-name">export</span> <span class="token assign-left variable">CLASSPATH</span><span class="token operator">=</span>.:<span class="token variable">$&#123;JAVA_HOME&#125;</span>/lib:<span class="token variable">$&#123;JRE_HOME&#125;</span>/lib

<span class="token builtin class-name">export</span> <span class="token assign-left variable"><span class="token environment constant">PATH</span></span><span class="token operator">=</span><span class="token variable">$&#123;JAVA_HOME&#125;</span>/bin:<span class="token environment constant">$PATH</span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516121946353.png" alt="image-20220516121946353"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#让环境变量生效：</span>
<span class="token builtin class-name">source</span> ~/.bashrc

<span class="token comment">#验证：</span>
java -version</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516121950307.png" alt="image-20220516121950307"> </p>
<p>进入hadoop2、hadoop3按照上述步骤配置jdk、环境变量并验证</p>
<h2 id="7-安装hadoop"><a href="#7-安装hadoop" class="headerlink" title="(7).安装hadoop"></a>(7).安装hadoop</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#切换至installfile目录解压hadoop安装包：</span>
<span class="token builtin class-name">cd</span> /root/installfile

<span class="token comment">#解压至soft目录下</span>
<span class="token function">tar</span> -zxvf hadoop-3.1.3.tar.gz -C ~/soft

<span class="token comment">#切换至soft目录：</span>
<span class="token builtin class-name">cd</span> /root/soft

<span class="token comment">#创建软连接：</span>
<span class="token function">ln</span> -s hadoop-3.1.3 hadoop</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516121954599.png" alt="image-20220516121954599"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#配置环境变量：</span>
<span class="token function">vi</span> ~/.bashrc

<span class="token comment">#内容如下：</span>
<span class="token builtin class-name">export</span> <span class="token assign-left variable">HADOOP_HOME</span><span class="token operator">=~</span>/soft/hadoop

<span class="token builtin class-name">export</span> <span class="token assign-left variable"><span class="token environment constant">PATH</span></span><span class="token operator">=</span><span class="token environment constant">$PATH</span><span class="token builtin class-name">:</span><span class="token variable">$HADOOP_HOME</span>/bin:<span class="token variable">$HADOOP_HOME</span>/sbin</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516121958454.png" alt="image-20220516121958454"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#让环境变量生效：</span>
<span class="token builtin class-name">source</span> ~/.bashrc

<span class="token comment">#验证：</span>
hadoop version</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122002381.png" alt="image-20220516122002381"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#进入hadoop配置目录：</span>
<span class="token builtin class-name">cd</span> <span class="token variable">$HADOOP_HOME</span>/etc/hadoop

<span class="token comment">#在hadoop-env.sh中配置JAVA_HOME路径：</span>
<span class="token function">vi</span> hadoop-env.sh</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122006516.png" alt="image-20220516122006516"> </p>
<p>配置core-site.xml：vi core-site.xml</p>
<p>在<configuration>和</configuration>之间添加如下内容：</p>
<pre class="language-markup" data-language="markup"><code class="language-markup"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>hadoop.tmp.dir<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>/opt/hadoop_data/tmp<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>description</span><span class="token punctuation">></span></span>Abase for other temporary directories.<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>description</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>fs.default.name<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
​    <span class="token comment">&lt;!-- hadoop1的内网IP地址 --></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>hdfs://hadoop1:9000<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

  <span class="token comment">&lt;!-- 指定NameNode的地址 --></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>fs.defaultFS<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>hdfs://hadoop1:8020<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122011920.png" alt="image-20220516122011920"> </p>
<p>配置hdfs-site.xml：vi hdfs-site.xml</p>
<p>在<configuration>和</configuration>之间添加如下内容：</p>
<pre class="language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- 指定NameNode的web端访问地址 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>dfs.namenode.http-address<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>hadoop1:9870<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

  <span class="token comment">&lt;!-- 设置SecondaryNameNode(2NN)的web端访问地址 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>dfs.namenode.secondary.http-address<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>hadoop3:9868<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>dfs.name.dir<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>/opt/hadoop_data/dfs/name<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>description</span><span class="token punctuation">></span></span>Path on the local filesystem where theNameNode stores the namespace and transactions logs persistently.<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>description</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>dfs.data.dir<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>/opt/hadoop_data/dfs/data<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>description</span><span class="token punctuation">></span></span>Comma separated list of paths on the localfilesystem of a DataNode where it should store its blocks.<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>description</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>dfs.replication<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>dfs.permissions<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>true<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>description</span><span class="token punctuation">></span></span>need not permissions<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>description</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122016807.png" alt="image-20220516122016807"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122021019.png" alt="image-20220516122021019"> </p>
<p>配置yarn-site.xml：vi yarn-site.xml</p>
<p>在<configuration>和</configuration>之间添加如下内容：</p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token operator">&lt;</span><span class="token operator">!</span>-- 指定MapReduce走shuffle --<span class="token operator">></span>

<span class="token operator">&lt;</span>property<span class="token operator">></span>
  <span class="token operator">&lt;</span>name<span class="token operator">></span>yarn.nodemanager.aux-services<span class="token operator">&lt;</span>/name<span class="token operator">></span>
  <span class="token operator">&lt;</span>value<span class="token operator">></span>mapreduce_shuffle<span class="token operator">&lt;</span>/value<span class="token operator">></span>
<span class="token operator">&lt;</span>/property<span class="token operator">></span>

<span class="token operator">&lt;</span><span class="token operator">!</span>-- 指定ResourceManager的地址 --<span class="token operator">></span>
<span class="token operator">&lt;</span>property<span class="token operator">></span>
  <span class="token operator">&lt;</span>name<span class="token operator">></span>yarn.resourcemanager.hostname<span class="token operator">&lt;</span>/name<span class="token operator">></span>
  <span class="token operator">&lt;</span>value<span class="token operator">></span>hadoop<span class="token operator"><span class="token file-descriptor important">2</span>&lt;</span>/value<span class="token operator">></span>
<span class="token operator">&lt;</span>/property<span class="token operator">></span>

<span class="token operator">&lt;</span>property<span class="token operator">></span>
  <span class="token operator">&lt;</span>description<span class="token operator">></span>The address of the applications manager interface <span class="token keyword">in</span> the RM.<span class="token operator">&lt;</span>/description<span class="token operator">></span>
  <span class="token operator">&lt;</span>name<span class="token operator">></span>yarn.resourcemanager.address<span class="token operator">&lt;</span>/name<span class="token operator">></span>
  <span class="token operator">&lt;</span>value<span class="token operator">></span><span class="token variable">$&#123;yarn.resourcemanager.hostname&#125;</span>:803<span class="token operator"><span class="token file-descriptor important">2</span>&lt;</span>/value<span class="token operator">></span>
<span class="token operator">&lt;</span>/property<span class="token operator">></span>

<span class="token operator">&lt;</span>property<span class="token operator">></span>
  <span class="token operator">&lt;</span>description<span class="token operator">></span>The address of the scheduler interface.<span class="token operator">&lt;</span>/description<span class="token operator">></span>
  <span class="token operator">&lt;</span>name<span class="token operator">></span>yarn.resourcemanager.scheduler.address<span class="token operator">&lt;</span>/name<span class="token operator">></span>
  <span class="token operator">&lt;</span>value<span class="token operator">></span><span class="token variable">$&#123;yarn.resourcemanager.hostname&#125;</span>:803<span class="token operator"><span class="token file-descriptor important">0</span>&lt;</span>/value<span class="token operator">></span>
<span class="token operator">&lt;</span>/property<span class="token operator">></span>

<span class="token operator">&lt;</span>property<span class="token operator">></span>
  <span class="token operator">&lt;</span>description<span class="token operator">></span>The http address of the RM web application.<span class="token operator">&lt;</span>/description<span class="token operator">></span>
  <span class="token operator">&lt;</span>name<span class="token operator">></span>yarn.resourcemanager.webapp.address<span class="token operator">&lt;</span>/name<span class="token operator">></span>
  <span class="token operator">&lt;</span>value<span class="token operator">></span><span class="token variable">$&#123;yarn.resourcemanager.hostname&#125;</span>:808<span class="token operator"><span class="token file-descriptor important">8</span>&lt;</span>/value<span class="token operator">></span>

<span class="token operator">&lt;</span>/property<span class="token operator">></span>

<span class="token operator">&lt;</span>property<span class="token operator">></span>
  <span class="token operator">&lt;</span>description<span class="token operator">></span>The https adddress of the RM web application.<span class="token operator">&lt;</span>/description<span class="token operator">></span>
  <span class="token operator">&lt;</span>name<span class="token operator">></span>yarn.resourcemanager.webapp.https.address<span class="token operator">&lt;</span>/name<span class="token operator">></span>
  <span class="token operator">&lt;</span>value<span class="token operator">></span><span class="token variable">$&#123;yarn.resourcemanager.hostname&#125;</span>:809<span class="token operator"><span class="token file-descriptor important">0</span>&lt;</span>/value<span class="token operator">></span>
<span class="token operator">&lt;</span>/property<span class="token operator">></span>

<span class="token operator">&lt;</span>property<span class="token operator">></span>
  <span class="token operator">&lt;</span>name<span class="token operator">></span>yarn.resourcemanager.resource-tracker.address<span class="token operator">&lt;</span>/name<span class="token operator">></span>
  <span class="token operator">&lt;</span>value<span class="token operator">></span><span class="token variable">$&#123;yarn.resourcemanager.hostname&#125;</span>:803<span class="token operator"><span class="token file-descriptor important">1</span>&lt;</span>/value<span class="token operator">></span>
<span class="token operator">&lt;</span>/property<span class="token operator">></span>

<span class="token operator">&lt;</span>property<span class="token operator">></span>
  <span class="token operator">&lt;</span>description<span class="token operator">></span>The address of the RM admin interface.<span class="token operator">&lt;</span>/description<span class="token operator">></span>
  <span class="token operator">&lt;</span>name<span class="token operator">></span>yarn.resourcemanager.admin.address<span class="token operator">&lt;</span>/name<span class="token operator">></span>
  <span class="token operator">&lt;</span>value<span class="token operator">></span><span class="token variable">$&#123;yarn.resourcemanager.hostname&#125;</span>:803<span class="token operator"><span class="token file-descriptor important">3</span>&lt;</span>/value<span class="token operator">></span>
<span class="token operator">&lt;</span>/property<span class="token operator">></span>

<span class="token operator">&lt;</span>property<span class="token operator">></span>
  <span class="token operator">&lt;</span>name<span class="token operator">></span>yarn.scheduler.maximum-allocation-mb<span class="token operator">&lt;</span>/name<span class="token operator">></span>
  <span class="token operator">&lt;</span>value<span class="token operator">></span><span class="token number">204</span><span class="token operator"><span class="token file-descriptor important">8</span>&lt;</span>/value<span class="token operator">></span>
  <span class="token operator">&lt;</span>discription<span class="token operator">></span>每个节点可用内存,单位MB,默认8182MB<span class="token operator">&lt;</span>/discription<span class="token operator">></span>
<span class="token operator">&lt;</span>/property<span class="token operator">></span>

<span class="token operator">&lt;</span>property<span class="token operator">></span>
  <span class="token operator">&lt;</span>name<span class="token operator">></span>yarn.nodemanager.vmem-pmem-ratio<span class="token operator">&lt;</span>/name<span class="token operator">></span>
  <span class="token operator">&lt;</span>value<span class="token operator">></span><span class="token number">2</span>.<span class="token operator"><span class="token file-descriptor important">1</span>&lt;</span>/value<span class="token operator">></span>
<span class="token operator">&lt;</span>/property<span class="token operator">></span>

<span class="token operator">&lt;</span>property<span class="token operator">></span>
  <span class="token operator">&lt;</span>name<span class="token operator">></span>yarn.nodemanager.resource.memory-mb<span class="token operator">&lt;</span>/name<span class="token operator">></span>
  <span class="token operator">&lt;</span>value<span class="token operator">></span><span class="token number">204</span><span class="token operator"><span class="token file-descriptor important">8</span>&lt;</span>/value<span class="token operator">></span>
<span class="token operator">&lt;</span>/property<span class="token operator">></span>

<span class="token operator">&lt;</span>property<span class="token operator">></span>
  <span class="token operator">&lt;</span>name<span class="token operator">></span>yarn.nodemanager.vmem-check-enabled<span class="token operator">&lt;</span>/name<span class="token operator">></span>
  <span class="token operator">&lt;</span>value<span class="token operator">></span>false<span class="token operator">&lt;</span>/value<span class="token operator">></span>
<span class="token operator">&lt;</span>/property<span class="token operator">></span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122026970.png" alt="image-20220516122026970"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122030561.png" alt="image-20220516122030561"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122034104.png" alt="image-20220516122034104"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#复制并且配置mapred-site.xml：</span>

<span class="token function">cp</span> mapred-site.xml mapred-site.xml.template

<span class="token function">vi</span> mapred-site.xml</code></pre>

<p>在<configuration>和</configuration>之间添加如下内容：</p>
<pre class="language-markup" data-language="markup"><code class="language-markup"><span class="token comment">&lt;!-- 指定MapReduce程序运行在Yarn上的地址 --></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>mapreduce.framework.name<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>yarn<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
 <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>mapred.job.tracker<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
      <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>hadoop1:49001<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>mapred.local.dir<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
​   <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>/opt/hadoop_data/var<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>yarn.app.mapreduce.am.env<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>HADOOP_MAPRED_HOME=/root/soft/hadoop<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>mapreduce.map.env<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>HADOOP_MAPRED_HOME=/root/soft/hadoop<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>mapreduce.reduce.env<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>HADOOP_MAPRED_HOME=/root/soft/hadoop<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122039094.png" alt="image-20220516122039094"> </p>
<p>配置workers，将三个主机名添加进去：vi workers</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122042633.png" alt="image-20220516122042633"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#进入/sbin目录下：</span>
<span class="token builtin class-name">cd</span> /root/soft/sbin/

<span class="token comment">#修改start-dfs.sh和stop-dfs.sh在这两个文件开头加如下内容：</span>
<span class="token assign-left variable">HDFS_DATANODE_USER</span><span class="token operator">=</span>root

<span class="token assign-left variable">HADOOP_SECURE_SECURE_USER</span><span class="token operator">=</span>root

<span class="token assign-left variable">HDFS_NAMENODE_USER</span><span class="token operator">=</span>root

<span class="token assign-left variable">HDFS_SECONDARYNAMENODE_USER</span><span class="token operator">=</span>root</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122046435.png" alt="image-20220516122046435"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#修改start-yarn.sh和stop-yarn.sh在这两个文件开头加如下内容：</span>
<span class="token assign-left variable">YARN_RESOURCEMANAGER_USER</span><span class="token operator">=</span>root

<span class="token assign-left variable">HADOOP_SECURE_DN_USER</span><span class="token operator">=</span>root

<span class="token assign-left variable">YARN_NODEMANAGER_USER</span><span class="token operator">=</span>root</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122050361.png" alt="image-20220516122050361"> </p>
<p>切换到soft目录下：cd &#x2F;root&#x2F;soft</p>
<p>使用xsync脚本将hadoop-3.1.3发送到hadoop2、hadoop3：</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122054081.png" alt="image-20220516122054081"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#切换hadoop2、hadoop3在soft目录下创建hadoop-3.1.3的软连接：</span>
<span class="token function">ln</span> -s hadoop-3.1.3 hadoop

<span class="token comment">#配置hadoop环境变量：</span>
<span class="token function">vi</span> ~/.bashrc

<span class="token comment">#内容如下：</span>
<span class="token builtin class-name">export</span> <span class="token assign-left variable">HADOOP_HOME</span><span class="token operator">=~</span>/soft/hadoop
<span class="token builtin class-name">export</span> <span class="token assign-left variable"><span class="token environment constant">PATH</span></span><span class="token operator">=</span><span class="token environment constant">$PATH</span><span class="token builtin class-name">:</span><span class="token variable">$HADOOP_HOME</span>/bin:<span class="token variable">$HADOOP_HOME</span>/sbin

<span class="token comment">#让环境变量生效：</span>
<span class="token builtin class-name">source</span> ~/.bashrc

<span class="token comment">#验证：</span>
hadoop version</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122058346.png" alt="image-20220516122058346"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122102094.png" alt="image-20220516122102094"> </p>
<h2 id="8-启动hadoop"><a href="#8-启动hadoop" class="headerlink" title="(8).启动hadoop"></a>(8).启动hadoop</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#格式化hadoop：</span>
hadoop namenode -format</code></pre>

<p>注：hadoop只能格式化一次，在下面出现successfully formatted为格式化成功，这里由于我已经格式化了，就不附截图了。</p>
<p>在hadoop1启动hdfs：start-dfs.sh</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122107291.png" alt="image-20220516122107291"> </p>
<p>在hadoop2启动yarn：start-yarn.sh</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122112228.png" alt="image-20220516122112228"> </p>
<p>验证进程：</p>
<p>在hadoop1、hadoop2、hadoop3分别输入：jps</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122116494.png" alt="image-20220516122116494"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122120013.png" alt="image-20220516122120013"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122123607.png" alt="image-20220516122123607"> </p>
<p>关闭防火墙：systemctl stop firewalld</p>
<p>在浏览器输入：192.168.246.132:9870</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516140133885.png" alt="image-20220516140133885"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122128674.png" alt="image-20220516122128674"> </p>
<p>在浏览器输入：192.168.246.134:8088</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122132496.png" alt="image-20220516122132496"> </p>
<p>在浏览器端可查看每台服务器状态：</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122138080.png" alt="image-20220516122138080"> </p>
<h2 id="9-简单使用hadoop"><a href="#9-简单使用hadoop" class="headerlink" title="(9).简单使用hadoop"></a>(9).简单使用hadoop</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#查看hdfs的根目录：</span>
hdfs dfs -ls /</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122143737.png" alt="image-20220516122143737"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#在根目录下创建文件夹：</span>
hdfs dfs -mkdir /data</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122147922.png" alt="image-20220516122147922"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#将linux本地文件上传到hdfs：</span>
hdfs dfs -put emp.csv /</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122151618.png" alt="image-20220516122151618"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#移动emp.csv的位置到/data目录下：</span>
hdfs dfs -mv /emp.csv /data</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122155106.png" alt="image-20220516122155106"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#将data目录下的emp.csv复制到hdfs的根目录下：</span>
hdfs dfs -cp /data/emp.csv /emp-copy.csv</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122159630.png" alt="image-20220516122159630"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#查看emp.csv文件内容：</span>
hdfs dfs -cat /emp-copy.csv</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122204310.png" alt="image-20220516122204310"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#删除文件emp-copy.csv：</span>
hdfs dfs -rm /emp-copy.csv 

<span class="token comment">#删除data文件夹:</span>
hdfs dfs -rm -r /data</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122209350.png" alt="image-20220516122209350"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122212683.png" alt="image-20220516122212683"> </p>
<p>使用wordcount脚本（自己编写的），对某个文件里面的字符进行统计</p>
<p>在linux本地创建1.txt文件并上传到hdfs根目录下的input（上面已有步骤，直接附截图）：</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122216665.png" alt="image-20220516122216665"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122220619.png" alt="image-20220516122220619"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#运行脚本：</span>
hadoop jar wordcount-1.0-SNAPSHOT.jar org.example.MyMain /input/1.txt /output/wordcount</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122224444.png" alt="image-20220516122224444"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#查看结果：</span>
hdfs dfs -cat /output/wordcount/part-r-00000</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122228709.png" alt="image-20220516122228709"> </p>
<p>在浏览器界面（9870）也可查看hdfs的文件存放情况：</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122232821.png" alt="image-20220516122232821"> </p>
<h1 id="2-ZooKeeper集群搭建及使用"><a href="#2-ZooKeeper集群搭建及使用" class="headerlink" title="2.ZooKeeper集群搭建及使用"></a>2.ZooKeeper集群搭建及使用</h1><h2 id="1-下载zookeeper安装包并解压"><a href="#1-下载zookeeper安装包并解压" class="headerlink" title="(1).下载zookeeper安装包并解压"></a>(1).下载zookeeper安装包并解压</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token function">tar</span> -zxvf zookeeper-3.4.9.tar.gz -C ~/soft</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122236855.png" alt="image-20220516122236855"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#切换至soft目录：</span>
<span class="token builtin class-name">cd</span> /root/soft

<span class="token comment">#创建软连接：</span>
<span class="token function">ln</span> -s zookeeper-3.4.9 zookeeper

<span class="token comment">#同步zookeeper至其他机器：</span>
xsync zookeeper-3.4.9</code></pre>

<p>切换hadoop2、hadoop3创建软连接</p>
<h2 id="2-配置环境变量"><a href="#2-配置环境变量" class="headerlink" title="(2).配置环境变量"></a>(2).配置环境变量</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token function">vi</span> ~/.bashrc
<span class="token comment">#内容如下：</span>
<span class="token builtin class-name">export</span> <span class="token assign-left variable">ZOOKEEPER_HOME</span><span class="token operator">=</span>/root/soft/zookeeper

<span class="token builtin class-name">export</span> <span class="token assign-left variable"><span class="token environment constant">PATH</span></span><span class="token operator">=</span><span class="token variable">$ZOOKEEPER_HOME</span>/bin:<span class="token environment constant">$PATH</span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122242022.png" alt="image-20220516122242022"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#让环境变量生效：</span>
<span class="token builtin class-name">source</span> ~/.bashrc</code></pre>

<p>每一台都需要配置环境变量，在hadoop2、hadoop3重复（2）步骤</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122246648.png" alt="image-20220516122246648"> </p>
<h2 id="3-配置zoo-cfg"><a href="#3-配置zoo-cfg" class="headerlink" title="(3).配置zoo.cfg"></a>(3).配置zoo.cfg</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#进入conf目录：</span>
<span class="token builtin class-name">cd</span> zookeeper/conf/

<span class="token comment">#复制zoo_sample.cf：</span>
<span class="token function">cp</span> zoo_sample.cfg zoo.cfg</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122251044.png" alt="image-20220516122251044"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#编辑zoo.cfg：</span>
<span class="token function">vi</span> zoo.cfg

<span class="token comment">#修改：</span>
<span class="token assign-left variable">dataDir</span><span class="token operator">=</span>/root/soft/zookeeper/tmp</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122255307.png" alt="image-20220516122255307"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#末尾添加：</span>
server.1<span class="token operator">=</span>hadoop1:2888:3888

server.2<span class="token operator">=</span>hadoop2:2888:3888

server.3<span class="token operator">=</span>hadoop3:2888:3888</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122258768.png" alt="image-20220516122258768"> </p>
<p>server.A&#x3D;B: C: D。</p>
<p>A:机器编号  </p>
<p>B:主机名  </p>
<p>C: Leader与Follower的访问端口 </p>
<p>D:选举Leader接口</p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#同步zoo.cfg：</span>
xsync zoo.cfg</code></pre>

<p>配置服务器编号：</p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#进入zookeeper：</span>
<span class="token builtin class-name">cd</span> <span class="token variable">$ZOOKEEPER_HOME</span>

<span class="token comment">#创建数据存放目录：</span>
<span class="token function">mkdir</span> zkData

<span class="token comment">#编辑myid：.</span>
<span class="token function">vi</span> zkData/myid</code></pre>

<p>内容为：1</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122303679.png" alt="image-20220516122303679"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122307298.png" alt="image-20220516122307298"> </p>
<p>在hadoop2中的myid添加内容为：2</p>
<p>在hadoop3中的myid添加内容为：3</p>
<h2 id="4-编写zookeeper脚本"><a href="#4-编写zookeeper脚本" class="headerlink" title="(4).编写zookeeper脚本"></a>(4).编写zookeeper脚本</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#进入bin目录下：</span>
<span class="token builtin class-name">cd</span> ~/bin

<span class="token comment">#创建脚本：</span>
<span class="token function">vi</span> zk.sh</code></pre>

<p>内容如下：</p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token shebang important">#!/bin/bash</span>
<span class="token keyword">case</span> <span class="token variable">$1</span> <span class="token keyword">in</span>
<span class="token string">"start"</span><span class="token punctuation">)</span><span class="token punctuation">&#123;</span>
  <span class="token keyword">for</span> <span class="token for-or-select variable">i</span> <span class="token keyword">in</span> hadoop1 hadoop2 hadoop3
  <span class="token keyword">do</span>
​    <span class="token builtin class-name">echo</span> <span class="token string">" --------启动 <span class="token variable">$i</span> zookeeper-------"</span>
​    <span class="token function">ssh</span> <span class="token variable">$i</span> <span class="token string">"zkServer.sh start "</span>
  <span class="token keyword">done</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token string">"stop"</span><span class="token punctuation">)</span><span class="token punctuation">&#123;</span>
  <span class="token keyword">for</span> <span class="token for-or-select variable">i</span> <span class="token keyword">in</span> hadoop1 hadoop2 hadoop3
  <span class="token keyword">do</span>
​    <span class="token builtin class-name">echo</span> <span class="token string">" --------停止 <span class="token variable">$i</span> zookeeper-------"</span>
​    <span class="token function">ssh</span> <span class="token variable">$i</span> <span class="token string">"zkServer.sh stop"</span>
  <span class="token keyword">done</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token string">"status"</span><span class="token punctuation">)</span><span class="token punctuation">&#123;</span>
  <span class="token keyword">for</span> <span class="token for-or-select variable">i</span> <span class="token keyword">in</span> hadoop1 hadoop2 hadoop3
  <span class="token keyword">do</span>
​    <span class="token builtin class-name">echo</span> <span class="token string">" --------状态 <span class="token variable">$i</span> zookeeper-------"</span>
​    <span class="token function">ssh</span> <span class="token variable">$i</span> <span class="token string">"zkServer.sh status"</span>
  <span class="token keyword">done</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token keyword">esac</span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122311485.png" alt="image-20220516122311485"> </p>
<p>添加脚本执行权限：chmod u+x zk.sh</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122316821.png" alt="image-20220516122316821"> </p>
<h2 id="5-启动zookeeper集群"><a href="#5-启动zookeeper集群" class="headerlink" title="(5).启动zookeeper集群"></a>(5).启动zookeeper集群</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#启动zookeeper集群：</span>
zk.sh start</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122320281.png" alt="image-20220516122320281"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#查看各机器状态：</span>
zk.sh status</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122324340.png" alt="image-20220516122324340"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#停止zookeeper集群：</span>
zk.sh stop</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122328422.png" alt="image-20220516122328422"> </p>
<h2 id="6-zookeeper集群的简单使用"><a href="#6-zookeeper集群的简单使用" class="headerlink" title="(6).zookeeper集群的简单使用"></a>(6).zookeeper集群的简单使用</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#启动zookeeper集群：</span>
zk.sh start

<span class="token comment">#进入zookeeper命令行：</span>
zkCli.sh</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122331781.png" alt="image-20220516122331781"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#创建节点（节点有四种类型，永久节点、临时节点、永久序列化节点、临时序列化节点）：</span>
<span class="token comment"># -s 序列化 -e 临时节点 path  创建路径  data 节点数据</span>
create <span class="token punctuation">[</span>-s<span class="token punctuation">]</span> <span class="token punctuation">[</span>-e<span class="token punctuation">]</span> path data  

<span class="token comment">#创建demo临时节点：</span>
create -e /demo <span class="token number">321</span>

<span class="token comment">#查看根下的所有节点：</span>
<span class="token function">ls</span> /</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122336640.png" alt="image-20220516122336640"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#查看path下所有znode,以及zonde的属性：</span>
ls2 /demo</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122340206.png" alt="image-20220516122340206"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#拿到/demo的数据：</span>
get /demo</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122344420.png" alt="image-20220516122344420"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#修改/demo的数据：</span>
<span class="token builtin class-name">set</span> /demo <span class="token number">456</span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122348066.png" alt="image-20220516122348066"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#递归删除节点：</span>
rmr /demo</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122352849.png" alt="image-20220516122352849"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#查看历史记录：</span>
<span class="token function">history</span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122356338.png" alt="image-20220516122356338"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#退出zookeeper命令行：</span>
quit</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122400137.png" alt="image-20220516122400137"> </p>
<h1 id="3-HBase集群搭建及使用"><a href="#3-HBase集群搭建及使用" class="headerlink" title="3.HBase集群搭建及使用"></a>3.HBase集群搭建及使用</h1><h2 id="1-查看hbase与jdk、hadoop的版本匹配；"><a href="#1-查看hbase与jdk、hadoop的版本匹配；" class="headerlink" title="(1).查看hbase与jdk、hadoop的版本匹配；"></a>(1).查看hbase与jdk、hadoop的版本匹配；</h2><p><img src="/hexo/2022/05/16/hadoop/image-20220516122405362.png" alt="image-20220516122405362"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122409109.png" alt="image-20220516122409109"> </p>
<h2 id="2-集群规划"><a href="#2-集群规划" class="headerlink" title="(2).集群规划"></a>(2).集群规划</h2><p><img src="/hexo/2022/05/16/hadoop/image-20220516122412571.png" alt="image-20220516122412571"> </p>
<h2 id="3-下载、解压hbase安装包"><a href="#3-下载、解压hbase安装包" class="headerlink" title="(3).下载、解压hbase安装包"></a>(3).下载、解压hbase安装包</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#切换到installfile：</span>
<span class="token builtin class-name">cd</span> /root/installfile

<span class="token comment">#解压至soft目录下：</span>
<span class="token function">tar</span> -zxvf hbase-2.4.11-bin.tar.gz -C ~/soft</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122416499.png" alt="image-20220516122416499"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#切换至soft目录：</span>
<span class="token builtin class-name">cd</span> /root/soft

<span class="token comment">#创建软连接：</span>
<span class="token function">ln</span> -s hbase-2.4.11 hbase

<span class="token comment">#同步zookeeper至其他机器：</span>
xsync hbase-2.4.11

<span class="token comment">#切换hadoop2、hadoop3创建软连接</span></code></pre>

<p> (4).配置环境变量；</p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token function">vi</span> ~/.bashrc

<span class="token comment">#内容如下：</span>
<span class="token builtin class-name">export</span> <span class="token assign-left variable">HBASE_HOME</span><span class="token operator">=~</span>/soft/hbase-2.4.11

<span class="token builtin class-name">export</span> <span class="token assign-left variable"><span class="token environment constant">PATH</span></span><span class="token operator">=</span><span class="token variable">$HBASE_HOME</span>/bin:<span class="token environment constant">$PATH</span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122421127.png" alt="image-20220516122421127"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#让环境变量生效：</span>
<span class="token builtin class-name">source</span> ~/.bashrc

<span class="token comment">#验证：</span>
hbase version</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122426092.png" alt="image-20220516122426092"> </p>
<p>每一台都需要配置环境变量，在hadoop2、hadoop3重复（4）步骤</p>
<h2 id="5-配置hbase-site-xml"><a href="#5-配置hbase-site-xml" class="headerlink" title="(5).配置hbase-site.xml"></a>(5).配置hbase-site.xml</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#切换到conf目录：</span>
<span class="token builtin class-name">cd</span> <span class="token variable">$HBASE_HOME</span>/conf

<span class="token comment">#编辑hbase-site.xml：</span>
<span class="token function">vi</span> hbase-site.xml</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122430589.png" alt="image-20220516122430589"> </p>
<p>在<configuration>和</configuration>之间添加如下内容：</p>
<pre class="language-markup" data-language="markup"><code class="language-markup"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>hbase.rootdir<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>hdfs://hadoop1:8020/hbase<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>hbase.cluster.distributed<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>true<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
​     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>hbase.zookeeper.quorum<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
​     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>hadoop1,hadoop2,hadoop3<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>hbase.zookeeper.property.dataDir<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>/root/soft/zookeeper/zkData<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>hbase.tmp.dir<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>/root/soft/hbase-2.4.11/tmp<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span>

  <span class="token comment">&lt;!-- 在分布式的情况下一定要设置，不然容易出现Hmaster起不来的情况 --></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>property</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>name</span><span class="token punctuation">></span></span>hbase.unsafe.stream.capability.enforce<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>name</span><span class="token punctuation">></span></span>
​    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>value</span><span class="token punctuation">></span></span>false<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>value</span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>property</span><span class="token punctuation">></span></span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122435139.png" alt="image-20220516122435139"> </p>
<h2 id="6-配置regionservers"><a href="#6-配置regionservers" class="headerlink" title="(6).配置regionservers"></a>(6).配置regionservers</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#编辑regionservers：</span>
<span class="token function">vi</span> regionservers 

<span class="token comment">#删除原有的localhost，添加如下内容： </span>
hadoop1
hadoop2
hadoop3</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122439505.png" alt="image-20220516122439505"> </p>
<h2 id="7-配置备用master"><a href="#7-配置备用master" class="headerlink" title="(7).配置备用master"></a>(7).配置备用master</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#编辑backup-masters：</span>
<span class="token function">vi</span> backup-masters 

<span class="token comment">#添加内容为：</span>
hadoop2</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122443768.png" alt="image-20220516122443768"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122447722.png" alt="image-20220516122447722"> </p>
<h2 id="8-软连接hadoop配置文件到hbase配置目录并分发hbase；"><a href="#8-软连接hadoop配置文件到hbase配置目录并分发hbase；" class="headerlink" title="(8).软连接hadoop配置文件到hbase配置目录并分发hbase；"></a>(8).软连接hadoop配置文件到hbase配置目录并分发hbase；</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#软连接hadoop的core-site.xml到hbase：</span>
<span class="token function">ln</span> -s /root/soft/etc/core-site.xml core-site.xml

<span class="token comment">#软连接hadoop的hdfs-site.xml到hbase：</span>
<span class="token function">ln</span> -s /root/soft/etc/hdfs-site.xml hdfs-site.xml</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122452063.png" alt="image-20220516122452063"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#返回上一级目录：</span>
<span class="token builtin class-name">cd</span> <span class="token punctuation">..</span>

<span class="token comment">#同步conf文件夹：</span>
xsync conf</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122456356.png" alt="image-20220516122456356"> </p>
<h2 id="9-启动hbase集群"><a href="#9-启动hbase集群" class="headerlink" title="(9).启动hbase集群"></a>(9).启动hbase集群</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#启动hbase前需要先启动zookeeper、hadoop：</span>
zk.sh start
start-all.sh
start-hbase.sh

<span class="token comment">#或者分开启动hbase：</span>
hbase-daemon.sh start master
hbase-daemon.sh start regionserver</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122500574.png" alt="image-20220516122500574"> </p>
<p>分别在hadoop1、hadoop2、hadoop3输入jps查看节点：jps</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122505347.png" alt="image-20220516122505347"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122508629.png" alt="image-20220516122508629"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122512505.png" alt="image-20220516122512505"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122517185.png" alt="image-20220516122517185"> </p>
<p>进入浏览器查看：192.168.246.132:16010</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122524759.png" alt="image-20220516122524759"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#停止hbase集群：</span>
stop-hbase.sh

<span class="token comment">#如果无法关闭就分别关闭master、regionserver：</span>
hbase-daemons.sh stop regionserver

hbase-daemons.sh stop master</code></pre>

<h2 id="10-hbase集群的简单使用；"><a href="#10-hbase集群的简单使用；" class="headerlink" title="(10).hbase集群的简单使用；"></a>(10).hbase集群的简单使用；</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#启动hbase集群：</span>
start-hbase.sh

<span class="token comment">#进入hbase命令行：</span>
hbase shell</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122531557.png" alt="image-20220516122531557"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#查看所有表：</span>
list</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122537346.png" alt="image-20220516122537346"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#创建stu表：</span>
create <span class="token string">'stu'</span>,<span class="token string">'info'</span>,<span class="token string">'no'</span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122542755.png" alt="image-20220516122542755"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#查看表结构：</span>
describe <span class="token string">'stu'</span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122546736.png" alt="image-20220516122546736"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#启用或禁用表：</span>
is_enabled <span class="token string">'stu'</span>

is_disabled <span class="token string">'stu'</span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122551001.png" alt="image-20220516122551001"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#向stu表添加数据：</span>
put <span class="token string">'stu'</span>,<span class="token string">'1001'</span>,<span class="token string">'info:name'</span>,<span class="token string">'HYX'</span>

<span class="token comment">#扫描表数据：</span>
scan <span class="token string">'stu'</span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122555113.png" alt="image-20220516122555113"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#继续向stu表添加数据：</span>

put <span class="token string">'stu'</span>,<span class="token string">'1002'</span>,<span class="token string">'info:name'</span>,<span class="token string">'Jack'</span>

put <span class="token string">'stu'</span>,<span class="token string">'1002'</span>,<span class="token string">'info:age'</span>,<span class="token string">'22'</span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122559328.png" alt="image-20220516122559328"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#统计表记录数：</span>
count <span class="token string">'stu'</span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122604057.png" alt="image-20220516122604057"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#删除stu表需要禁用表：</span>
disable <span class="token string">'stu'</span>

<span class="token comment">#删除表：</span>
drop <span class="token string">'stu'</span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122607441.png" alt="image-20220516122607441"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#退出hbase命令行：</span>
<span class="token builtin class-name">exit</span> 或 quit</code></pre>

<h1 id="4-Kafka集群搭建及使用"><a href="#4-Kafka集群搭建及使用" class="headerlink" title="4.Kafka集群搭建及使用"></a>4.Kafka集群搭建及使用</h1><h2 id="1-集群规划"><a href="#1-集群规划" class="headerlink" title="(1).集群规划"></a>(1).集群规划</h2><p><img src="/hexo/2022/05/16/hadoop/image-20220516140250117.png" alt="image-20220516140250117"> </p>
<h2 id="2-下载并解压安装包"><a href="#2-下载并解压安装包" class="headerlink" title="(2).下载并解压安装包"></a>(2).下载并解压安装包</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#切换到installfile目录：</span>
<span class="token builtin class-name">cd</span> /root/installfile

<span class="token comment">#解压至soft目录下：</span>
<span class="token function">tar</span> -zxvf kafka_2.11-2.4.1.gz -C ~/soft</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122622290.png" alt="image-20220516122622290"></p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#切换至soft目录：</span>
<span class="token builtin class-name">cd</span> /root/soft

<span class="token comment">#创建软连接：</span>
<span class="token function">ln</span> -s kafka_2.11-2.4.1 kafka

<span class="token comment">#同步kafka至其他机器：</span>
xsync kafka_2.11-2.4.1</code></pre>

<p>切换hadoop2、hadoop3创建软连接</p>
<h2 id="3-配置环境变量"><a href="#3-配置环境变量" class="headerlink" title="(3).配置环境变量"></a>(3).配置环境变量</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token function">vi</span> ~/.bashrc

<span class="token comment">#内容如下：</span>
<span class="token builtin class-name">export</span> <span class="token assign-left variable">KAFKA_HOME</span><span class="token operator">=</span>/root/soft/kafka

<span class="token builtin class-name">export</span> <span class="token assign-left variable"><span class="token environment constant">PATH</span></span><span class="token operator">=</span><span class="token environment constant">$PATH</span><span class="token builtin class-name">:</span><span class="token variable">$KAFKA_HOME</span>/bin</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122628614.png" alt="image-20220516122628614"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#让环境变量生效：</span>
<span class="token builtin class-name">source</span> ~/.bashrc</code></pre>

<p>每一台都需要配置环境变量，在hadoop2、hadoop3重复（3）步骤</p>
<h2 id="4-分别在三台机器上创建logs目录"><a href="#4-分别在三台机器上创建logs目录" class="headerlink" title="(4).分别在三台机器上创建logs目录"></a>(4).分别在三台机器上创建logs目录</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#切换到kafka目录：</span>
<span class="token builtin class-name">cd</span> <span class="token variable">$KAFKA_HOME</span>

<span class="token comment">#创建logs目录：</span>
<span class="token function">mkdir</span> logs</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122633371.png" alt="image-20220516122633371"> </p>
<h2 id="5-修改配置文件server-properties"><a href="#5-修改配置文件server-properties" class="headerlink" title="(5).修改配置文件server.properties"></a>(5).修改配置文件server.properties</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#切换至config目录：</span>
<span class="token builtin class-name">cd</span> config

<span class="token comment">#编辑server.properties：</span>
<span class="token function">vi</span> server.properties</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122637275.png" alt="image-20220516122637275"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#修改内容如下：</span>
broker.id<span class="token operator">=</span><span class="token number">0</span>

<span class="token comment">#删除topic功能</span>
delete.topic.enable<span class="token operator">=</span>true

log.dirs<span class="token operator">=</span>/root/soft/kafka/logs

zookeeper.connect<span class="token operator">=</span>hadoop1:2181,hadoop2:2181,hadoop3:2181/kafka</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122641096.png" alt="image-20220516122641096"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122644972.png" alt="image-20220516122644972"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122649136.png" alt="image-20220516122649136"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#分发server.properties到hadoop2、hadoop3：</span>
xsync server.properties

<span class="token comment">#修改hadoop2的server.properties中</span>
broker.id<span class="token operator">=</span><span class="token number">1</span>

<span class="token comment">#修改hadoop3的server.properties中</span>
broker.id<span class="token operator">=</span><span class="token number">2</span></code></pre>

<h2 id="6-编写kafka脚本"><a href="#6-编写kafka脚本" class="headerlink" title="(6).编写kafka脚本"></a>(6).编写kafka脚本</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#进入bin目录下：</span>
<span class="token builtin class-name">cd</span> ~/bin

<span class="token comment">#创建脚本：</span>
<span class="token function">vi</span> kf.sh</code></pre>

<p>内容如下：</p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token shebang important">#!/bin/bash</span>
<span class="token keyword">case</span> <span class="token variable">$1</span> <span class="token keyword">in</span>
<span class="token string">"start"</span><span class="token punctuation">)</span><span class="token punctuation">&#123;</span>
  <span class="token keyword">for</span> <span class="token for-or-select variable">i</span> <span class="token keyword">in</span> hadoop1 hadoop2 hadoop3
  <span class="token keyword">do</span>
​    <span class="token builtin class-name">echo</span> <span class="token string">" --------启动 <span class="token variable">$i</span> Kafka-------"</span>
​    <span class="token function">ssh</span> <span class="token variable">$i</span> <span class="token string">"/root/soft/kafka/bin/kafka-server-start.sh -daemon /root/soft/kafka/config/server.properties "</span>
  <span class="token keyword">done</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token string">"stop"</span><span class="token punctuation">)</span><span class="token punctuation">&#123;</span>
  <span class="token keyword">for</span> <span class="token for-or-select variable">i</span> <span class="token keyword">in</span> hadoop1 hadoop2 hadoop3
  <span class="token keyword">do</span>
​    <span class="token builtin class-name">echo</span> <span class="token string">" --------停止 <span class="token variable">$i</span> Kafka-------"</span>
​    <span class="token function">ssh</span> <span class="token variable">$i</span> <span class="token string">"/root/soft/kafka/bin/kafka-server-stop.sh stop"</span>
  <span class="token keyword">done</span>
<span class="token punctuation">&#125;</span><span class="token punctuation">;</span><span class="token punctuation">;</span>
<span class="token keyword">esac</span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122655855.png" alt="image-20220516122655855"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#添加脚本执行权限：</span>
<span class="token function">chmod</span> u+x kf.sh</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122701672.png" alt="image-20220516122701672"> </p>
<h2 id="7-启动kafka集群"><a href="#7-启动kafka集群" class="headerlink" title="(7).启动kafka集群"></a>(7).启动kafka集群</h2><pre class="language-bash" data-language="bash"><code class="language-bash">启<span class="token comment">#动kafka集群需要先启动zookeeper集群：</span>
zk.sh start <span class="token operator">|</span>  kf.sh start</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122705626.png" alt="image-20220516122705626"> </p>
<p>使用jps查看三台机器的节点是否启动：jps</p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122709528.png" alt="image-20220516122709528"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122713433.png" alt="image-20220516122713433"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122716947.png" alt="image-20220516122716947"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#关闭kafka集群：</span>
kf.sh stop</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122721107.png" alt="image-20220516122721107"> </p>
<h2 id="8-kafka集群的简单使用"><a href="#8-kafka集群的简单使用" class="headerlink" title="(8).kafka集群的简单使用"></a>(8).kafka集群的简单使用</h2><pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#启动kafka集群：</span>
kf.sh start

<span class="token comment">#进入kafka目录：</span>
<span class="token builtin class-name">cd</span> <span class="token variable">$KAFKA_HOME</span>

<span class="token comment">#查看kafka topic列表：</span>
bin/kafka-topics.sh --zookeeper hadoop1:2181/kafka --list</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122725063.png" alt="image-20220516122725063"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#创建topic：</span>
bin/kafka-topics.sh --zookeeper hadoop1:2181/kafka <span class="token punctuation">\</span>
--create --replication-factor <span class="token number">3</span> --partitions <span class="token number">1</span> --topic demo</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122729379.png" alt="image-20220516122729379"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#删除topic：</span>
bin/kafka-topics.sh --zookeeper hadoop1:2181/kafka <span class="token punctuation">\</span>
--delete --topic demo</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122733878.png" alt="image-20220516122733878"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#发送消息：</span>
bin/kafka-console-producer.sh <span class="token punctuation">\</span>
--broker-list hadoop1:9092 --topic demo</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122737468.png" alt="image-20220516122737468"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#消费消息：</span>
bin/kafka-console-consumer.sh <span class="token punctuation">\</span>
--bootstrap-server hadoop1:9092 --from-beginning --topic demo</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122741682.png" alt="image-20220516122741682"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#查看某个topic的详情：</span>
bin/kafka-topics.sh --zookeeper hadoop1:2181/kafka <span class="token punctuation">\</span> --describe --topic demo</code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122746568.png" alt="image-20220516122746568"> </p>
<p><img src="/hexo/2022/05/16/hadoop/image-20220516122750832.png" alt="image-20220516122750832"> </p>
<pre class="language-bash" data-language="bash"><code class="language-bash"><span class="token comment">#修改分区数：</span>
bin/kafka-topics.sh --zookeeper hadoop1:2181/kafka --alter --topic demo --partitions <span class="token number">6</span></code></pre>

<p><img src="/hexo/2022/05/16/hadoop/image-20220516122757161.png" alt="image-20220516122757161"></p>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/hexo/about" rel="external nofollow noreferrer">成大事</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://chengdashia.gitee.io/hexo/hexo/2022/05/16/hadoop/">https://chengdashia.gitee.io/hexo/hexo/2022/05/16/hadoop/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/hexo/about" target="_blank">成大事</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/hexo/tags/hadoop/">
                                    <span class="chip bg-color">hadoop</span>
                                </a>
                            
                                <a href="/hexo/tags/zookeeper/">
                                    <span class="chip bg-color">zookeeper</span>
                                </a>
                            
                                <a href="/hexo/tags/kafka/">
                                    <span class="chip bg-color">kafka</span>
                                </a>
                            
                                <a href="/hexo/tags/hbase/">
                                    <span class="chip bg-color">hbase</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/hexo/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/hexo/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/hexo/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/hexo/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    
        <style>
    .valine-card {
        margin: 1.5rem auto;
    }

    .valine-card .card-content {
        padding: 20px 20px 5px 20px;
    }

    #vcomments textarea {
        box-sizing: border-box;
        background: url("/hexo/medias/comment_bg.png") 100% 100% no-repeat;
    }

    #vcomments p {
        margin: 2px 2px 10px;
        font-size: 1.05rem;
        line-height: 1.78rem;
    }

    #vcomments blockquote p {
        text-indent: 0.2rem;
    }

    #vcomments a {
        padding: 0 2px;
        color: #4cbf30;
        font-weight: 500;
        text-decoration: none;
    }

    #vcomments img {
        max-width: 100%;
        height: auto;
        cursor: pointer;
    }

    #vcomments ol li {
        list-style-type: decimal;
    }

    #vcomments ol,
    ul {
        display: block;
        padding-left: 2em;
        word-spacing: 0.05rem;
    }

    #vcomments ul li,
    ol li {
        display: list-item;
        line-height: 1.8rem;
        font-size: 1rem;
    }

    #vcomments ul li {
        list-style-type: disc;
    }

    #vcomments ul ul li {
        list-style-type: circle;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    #vcomments table, th, td {
        border: 0;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments h1 {
        font-size: 1.85rem;
        font-weight: bold;
        line-height: 2.2rem;
    }

    #vcomments h2 {
        font-size: 1.65rem;
        font-weight: bold;
        line-height: 1.9rem;
    }

    #vcomments h3 {
        font-size: 1.45rem;
        font-weight: bold;
        line-height: 1.7rem;
    }

    #vcomments h4 {
        font-size: 1.25rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    #vcomments h5 {
        font-size: 1.1rem;
        font-weight: bold;
        line-height: 1.4rem;
    }

    #vcomments h6 {
        font-size: 1rem;
        line-height: 1.3rem;
    }

    #vcomments p {
        font-size: 1rem;
        line-height: 1.5rem;
    }

    #vcomments hr {
        margin: 12px 0;
        border: 0;
        border-top: 1px solid #ccc;
    }

    #vcomments blockquote {
        margin: 15px 0;
        border-left: 5px solid #42b983;
        padding: 1rem 0.8rem 0.3rem 0.8rem;
        color: #666;
        background-color: rgba(66, 185, 131, .1);
    }

    #vcomments pre {
        font-family: monospace, monospace;
        padding: 1.2em;
        margin: .5em 0;
        background: #272822;
        overflow: auto;
        border-radius: 0.3em;
        tab-size: 4;
    }

    #vcomments code {
        font-family: monospace, monospace;
        padding: 1px 3px;
        font-size: 0.92rem;
        color: #e96900;
        background-color: #f8f8f8;
        border-radius: 2px;
    }

    #vcomments pre code {
        font-family: monospace, monospace;
        padding: 0;
        color: #e8eaf6;
        background-color: #272822;
    }

    #vcomments pre[class*="language-"] {
        padding: 1.2em;
        margin: .5em 0;
    }

    #vcomments code[class*="language-"],
    pre[class*="language-"] {
        color: #e8eaf6;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }

    #vcomments b,
    strong {
        font-weight: bold;
    }

    #vcomments dfn {
        font-style: italic;
    }

    #vcomments small {
        font-size: 85%;
    }

    #vcomments cite {
        font-style: normal;
    }

    #vcomments mark {
        background-color: #fcf8e3;
        padding: .2em;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }
</style>

<div class="card valine-card" data-aos="fade-up">
    <div class="comment_headling" style="font-size: 20px; font-weight: 700; position: relative; padding-left: 20px; top: 15px; padding-bottom: 5px;">
        <i class="fas fa-comments fa-fw" aria-hidden="true"></i>
        <span>评论</span>
    </div>
    <div id="vcomments" class="card-content" style="display: grid">
    </div>
</div>

<script src="/hexo/libs/valine/av-min.js"></script>
<script src="/hexo/libs/valine/Valine.min.js"></script>
<script>
    new Valine({
        el: '#vcomments',
        appId: 'SE8EiIL2vA7NGg6sPt1s1Sj6-gzGzoHsz',
        appKey: 'OIVUi4Sf5nRYKKniv3KP4oWE',
        notify: '' === 'true',
        verify: '' === 'true',
        visitor: '' === 'true',
        avatar: 'monsterid',
        pageSize: '5',
        lang: 'zh-cn',
        placeholder: '昵称填写qq可以显示qq头像和昵称哦~'
    });
</script>

<!--酷Q推送-->


    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="far fa-dot-circle"></i>&nbsp;本篇
            </div>
            <div class="card">
                <a href="/hexo/2022/05/16/hadoop/">
                    <div class="card-image">
                        
                        <img src="/hexo/medias/index/1.jpg" class="responsive-img" alt="hadoop 大数据集群的搭建以及使用">
                        
                        <span class="card-title">hadoop 大数据集群的搭建以及使用</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            hadoop 大数据集群的搭建以及使用
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2022-05-16
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/hexo/categories/hadoop/" class="post-category">
                                    hadoop
                                </a>
                            
                            
                        </span>
                    </div>
                </div>

                
                <div class="card-action article-tags">
                    
                    <a href="/hexo/tags/hadoop/">
                        <span class="chip bg-color">hadoop</span>
                    </a>
                    
                    <a href="/hexo/tags/zookeeper/">
                        <span class="chip bg-color">zookeeper</span>
                    </a>
                    
                    <a href="/hexo/tags/kafka/">
                        <span class="chip bg-color">kafka</span>
                    </a>
                    
                    <a href="/hexo/tags/hbase/">
                        <span class="chip bg-color">hbase</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                本篇&nbsp;<i class="far fa-dot-circle"></i>
            </div>
            <div class="card">
                <a href="/hexo/2022/05/16/hadoop/">
                    <div class="card-image">
                        
                        <img src="/hexo/medias/index/1.jpg" class="responsive-img" alt="hadoop 大数据集群的搭建以及使用">
                        
                        <span class="card-title">hadoop 大数据集群的搭建以及使用</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            hadoop 大数据集群的搭建以及使用
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2022-05-16
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/hexo/categories/hadoop/" class="post-category">
                                    hadoop
                                </a>
                            
                            
                        </span>
                    </div>
                </div>

                
                <div class="card-action article-tags">
                    
                    <a href="/hexo/tags/hadoop/">
                        <span class="chip bg-color">hadoop</span>
                    </a>
                    
                    <a href="/hexo/tags/zookeeper/">
                        <span class="chip bg-color">zookeeper</span>
                    </a>
                    
                    <a href="/hexo/tags/kafka/">
                        <span class="chip bg-color">kafka</span>
                    </a>
                    
                    <a href="/hexo/tags/hbase/">
                        <span class="chip bg-color">hbase</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>


<script>
    $('#articleContent').on('copy', function (e) {
        // IE8 or earlier browser is 'undefined'
        if (typeof window.getSelection === 'undefined') return;

        var selection = window.getSelection();
        // if the selection is short let's not annoy our users.
        if (('' + selection).length < Number.parseInt('120')) {
            return;
        }

        // create a div outside of the visible area and fill it with the selected text.
        var bodyElement = document.getElementsByTagName('body')[0];
        var newdiv = document.createElement('div');
        newdiv.style.position = 'absolute';
        newdiv.style.left = '-99999px';
        bodyElement.appendChild(newdiv);
        newdiv.appendChild(selection.getRangeAt(0).cloneContents());

        // we need a <pre> tag workaround.
        // otherwise the text inside "pre" loses all the line breaks!
        if (selection.getRangeAt(0).commonAncestorContainer.nodeName === 'PRE' || selection.getRangeAt(0).commonAncestorContainer.nodeName === 'CODE') {
            newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";
        }

        var url = document.location.href;
        newdiv.innerHTML += '<br />'
            + '来源: 成大事<br />'
            + '作者: 成大事<br />'
            + '文章链接: <a href="' + url + '">' + url + '</a><br />'
            + '本文章著作权归作者所有，任何形式的转载都请注明出处。';

        selection.selectAllChildren(newdiv);
        window.setTimeout(function () {bodyElement.removeChild(newdiv);}, 200);
    });
</script>


<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/hexo/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->


<!-- 代码块复制 -->

<script type="text/javascript" src="/hexo/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/hexo/libs/codeBlock/codeShrink.js"></script>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/hexo/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('1'),
            headingSelector: 'h1, h2, h3, h4, h5, h6'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h1, h2, h3, h4, h5, h6').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>


<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=default"></script>



    <footer class="page-footer bg-color">

    
        <link rel="stylesheet" href="/hexo/libs/aplayer/APlayer.min.css">
<style>
    .aplayer .aplayer-lrc p {
        
        font-size: 12px;
        font-weight: 700;
        line-height: 16px !important;
    }

    .aplayer .aplayer-lrc p.aplayer-lrc-current {
        
        font-size: 15px;
        color: #42b983;
    }

    
    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
        left: -66px !important;
    }

    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body:hover {
        left: 0px !important;
    }

    
</style>
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="playlist"
                   id="2943351980"
                   fixed='true'
                   autoplay='false'
                   theme='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.7'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="/hexo/libs/aplayer/APlayer.min.js"></script>
<script src="/hexo/libs/aplayer/Meting.min.js"></script>

    

    <div class="container row center-align"
         style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2022</span>
            
            <a href="/hexo/about" target="_blank">成大事</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
            
            
                
            
            
                <span id="busuanzi_container_site_pv">
                &nbsp;|&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;
                    <span id="busuanzi_value_site_pv" class="white-color"></span>
            </span>
            
            
                <span id="busuanzi_container_site_uv">
                &nbsp;|&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;
                    <span id="busuanzi_value_site_uv" class="white-color"></span>
            </span>
            
            <br>

            <!-- 运行天数提醒. -->
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/chengdashia" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:1847085602@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=1847085602" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 1847085602" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>








    <a href="" class="tooltipped" target="_blank" data-tooltip="访问我的CSDN" data-position="top" data-delay="50">
        <i class="fab fa-CSDN">c</i>
    </a>


</div>
    </div>
</footer>

<div class="progress-bar"></div>



    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/hexo/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/hexo/libs/materialize/materialize.min.js"></script>
    <script src="/hexo/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/hexo/libs/aos/aos.js"></script>
    <script src="/hexo/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/hexo/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/hexo/js/matery.js"></script>

    

    


    <!-- 雪花特效 -->
    

    <!-- 鼠标星星特效 -->
     
        <script type="text/javascript">
            // 只在桌面版网页启用特效
            var windowWidth = $(window).width();
            if (windowWidth > 768) {
                document.write('<script type="text/javascript" src="/hexo/libs/others/star.js"><\/script>');
            }
        </script>
    
    <!-- 动态标题 -->
    <script type="text/javascript"> var OriginTitile = document.title, st; 
        document.addEventListener("visibilitychange", function () { document.hidden ? (document.title = "Σ(っ °Д °;)っ喔哟，崩溃啦！", clearTimeout(st)) : (document.title = "φ(゜▽゜*)♪咦，又好了！", st = setTimeout(function () { document.title = OriginTitile }, 3e3)) })
    </script>
        


    <!-- 天气接口 -->
    

    


    
    <script src="/hexo/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/hexo/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    <!--腾讯兔小巢-->
    
    

    

    

    

</body>

</html>
